package com.ibenew.demo.bcspaneldemo.demo1.ui;

import android.content.Context;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.StaggeredGridLayoutManager;
import android.view.ViewGroup;

import com.ibenew.demo.bcspaneldemo.R;
import com.ibenew.demo.bcspaneldemo.weight.BaseRecyclerAdapter;
import com.ibenew.demo.bcspaneldemo.weight.RecyclerHolder;

import java.util.ArrayList;
import java.util.List;

public class TestRecyclearViewActivity extends AppCompatActivity {
    RecyclerView rv,rv1,rv2;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_test_recyclear_view);
        rv = (RecyclerView) findViewById(R.id.rv);
        rv1 = (RecyclerView) findViewById(R.id.rv1);
        rv2 = (RecyclerView) findViewById(R.id.rv2);
        List<String> list = new ArrayList<>();
        List<String> list1 = new ArrayList<>();
        List<String> list2 = new ArrayList<>();
        for (int i = 1; i < 6; i++) {
            for (int j = 1; j < 7; j++) {
                list.add(String.format("A%d%d", j, i));
                list1.add(String.format("B%d%d", j, i));
            }
        }
        list.remove("A15");
        list.remove("A25");
        list1.remove("B15");
        list1.remove("B25");
        list1.remove("B35");

        for (int i = 11; i < 100 ; i++) {
            if (i%10 > 8)
                continue;
            list2.add("C" + i);
        }

        RvAdater adater = new RvAdater(list, this, R.layout.item_rv);
        RvAdater adater1 = new RvAdater(list1, this, R.layout.item_rv);
        RvAdater adater2 = new RvAdater(list2, this, R.layout.item_rv);
        StaggeredGridLayoutManager sgm = new StaggeredGridLayoutManager(6, StaggeredGridLayoutManager.HORIZONTAL);
        StaggeredGridLayoutManager sgm1 = new StaggeredGridLayoutManager(6, StaggeredGridLayoutManager.HORIZONTAL);
        rv2.setLayoutManager(new GridLayoutManager(this,8));
        rv.setLayoutManager(sgm);
        rv1.setLayoutManager(sgm1);
        rv.setAdapter(adater);
        rv1.setAdapter(adater1);
        rv2.setAdapter(adater2);
    }

    private class RvAdater extends BaseRecyclerAdapter<String> {

        public RvAdater(List<String> mCollection, Context mCxt, int layoutId) {
            super(mCollection, mCxt, layoutId);
        }

        @Override
        public void convert(RecyclerHolder holder, String item) {
            int dp50 = getResources().getDimensionPixelSize(R.dimen.dp50);
            if (item.contains("A")) {
                holder.itemView.setLayoutParams(new ViewGroup.LayoutParams((item.equals("A14") || item.equals("A24")) ? dp50 * 2 : dp50, ViewGroup.LayoutParams.MATCH_PARENT));
            } else if (item.contains("B"))
                holder.itemView.setLayoutParams(new ViewGroup.LayoutParams((item.equals("B11") || item.equals("B21")|| item.equals("B31")) ? dp50 * 2 : dp50, ViewGroup.LayoutParams.MATCH_PARENT));
            else
                holder.itemView.setLayoutParams(new ViewGroup.LayoutParams((int)(dp50 * 1.2), ViewGroup.LayoutParams.WRAP_CONTENT));
            holder.setText(R.id.tv, item);
        }
    }
}
